package com.ruoyi.web.controller.member;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictType;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysMember;
import com.ruoyi.system.domain.SysMemberapp;
import com.ruoyi.system.domain.SysMemberbook;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/member")
public class SysMemberController extends BaseController {
    @Autowired
    private ISysMemberService iSysMemberService;
    @Autowired
    private ISysMemberappService iSysMemberappService;
    @Autowired
    private ISysMembernoteService iSysMembernoteService;
    @Autowired
    private ISysMemberbookService iSysMemberbookService;

    /**
     * 获取会员列表
     */
    @PreAuthorize("@ss.hasPermi('system:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMember member)
    {
        startPage();
        List<SysMember> list = iSysMemberService.selectMemberList(member);
        return getDataTable(list);
    }
    /**
     * 获取会员安装应用列表
     */
    @GetMapping(value = "applist/{memberId}")
    public TableDataInfo listapp(@PathVariable int memberId)
    {
        startPage();
        List<SysMemberapp> list = iSysMemberappService.selectMemberappList(memberId);
        return getDataTable(list);
    }
    /**
     *
     * 获取会员短信列表
     */
    @GetMapping(value = "notelist/{memberId}")
    public TableDataInfo listnote(@PathVariable int memberId)
    {
        startPage();
        List<SysMemberapp> list = iSysMembernoteService.selectMembernoteList(memberId);
        return getDataTable(list);
    }
    /**
     *
     * 获取会员通讯录列表
     */
    @GetMapping(value = "booklist/{memberId}")
    public TableDataInfo listbook(@PathVariable int memberId)
    {
        startPage();
        List<SysMemberbook> list = iSysMemberbookService.selectMemberbookList(memberId);
        return getDataTable(list);
    }
    /**
     * 根据通知会员编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:member:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable int memberId)
    {
        return AjaxResult.success(iSysMemberService.selectMemberById(memberId));
    }
    /**
     * 导出会员列表
     */
    @Log(title = "会员列表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:member:export')")
    @GetMapping("/export")
    public AjaxResult export(SysMember member)
    {
        List<SysMember> list = iSysMemberService.selectMemberList(member);
        ExcelUtil<SysMember> util = new ExcelUtil<SysMember>(SysMember.class);
        return util.exportExcel(list, "会员列表");
    }
}
